home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 5_5.lha / 5_5 / 5_5a.c < prev    next >
Text File  |  1993-08-08  |  666b  |  43 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. include <5.5A.h>
  6. tatic void treeprint(tree* head)
  7.  
  8.    if (head)
  9. switch (head->type)
  10.     {
  11.     case PLUS: case MINUS: case DIV: case MULT:
  12.     cout << "(";
  13.     treeprint(head->left);
  14.     cout << chr(head->type);
  15.     treeprint(head->right);
  16.     cout << ")";
  17.     break;
  18.  
  19.     case NEG:
  20.     cout << "-(";
  21.     treeprint(head->left);
  22.     cout << ")";
  23.     break;
  24.  
  25.     case NUMBER:
  26.     cout << head->value;
  27.     break;
  28.  
  29.     default:
  30.     error("unknown type within tree");
  31.     break;
  32.     }
  33.  
  34.    else
  35.        error("null node found");
  36.  
  37.  
  38. oid expr:: print()
  39.  
  40.    treeprint(head);
  41.  
  42.  
  43.